package jsonobj;

import com.google.gson.Gson;

import data.ClusterInfo;

public class ClusterIDInfo implements JSonObj {
	public String hostname;
	public String local_hostname;
	public int nodes;
	public int procs;
	public int rjobs;
	public int qjobs;
	public int db_id;
	public boolean isOn;
	
	public ClusterIDInfo(){}
	
	public ClusterIDInfo(ClusterInfo cf)
	{
		this.hostname = cf.hostname;
		this.local_hostname = cf.local_hostname;
		this.db_id = cf.db_id;
		this.isOn = cf.isConnected;
	}
	public ClusterIDInfo(String h, String lh, int i, boolean io)
	{
		this.hostname = h;
		this.local_hostname = lh;
		this.db_id = i;
		this.isOn = io;
	}
	
	public void setCurrentClusterStatus(java.sql.Connection conn)
	{
		int [] data = utils.Database.GetCurrentClusterStatus(conn,local_hostname.contains("big") ? "bc2" : "bc1");
		nodes = data[0];
		procs = data[1];
		rjobs = data[2];
		qjobs = data[3];
	}
	
	public String toString()
	{
		return new Gson().toJson(this);
	}
	
	public static ClusterIDInfo fromJSon(String json)
	{
		return new Gson().fromJson(json,ClusterIDInfo.class);
	}

}
